ci: set least-privilege GITHUB_TOKEN permissions#133
Merged
Conversation
Add top-level `permissions: contents: read` to every workflow. Without it, jobs inherit the repo-default token scope (often read-write), so a malicious dependency executing during install/build/test on a push to the default branch would hold a write-capable token. Read-only by default denies that; the publish job keeps its own job-level `id-token: write` block (job-level permissions override the top-level default), so trusted-publishing is unaffected. Complements the SHA-pinning: pinning stops untrusted code from running; this limits what it can do if it runs anyway. Fork-PR tokens are already forced read-only by GitHub; this closes the push-triggered path. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Least-privilege
GITHUB_TOKEN: adds top-levelpermissions: contents: readto every workflow.Jobs otherwise inherit the repo-default token scope (often read-write). A poisoned transitive dependency running during install/build/test on a push to the default branch would then hold a write-capable token (push commits, cut releases). Read-only by default denies that. Publish jobs keep their own job-level
id-token: write(job-level overrides the top-level default), so PyPI trusted publishing is unaffected.Defense-in-depth complement to the SHA-pinning: pinning stops untrusted code from running; this caps what it can do. Fork-PR tokens are already read-only by GitHub design — this closes the push-triggered path.
🤖 Generated with Claude Code